package com.mobilesales.android.util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class DateUtil {

	private static final String format = "yyyy-MM-dd HH:mm";
	
	public static Date parseDate(String dateString) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.ENGLISH);
			Date d = sdf.parse(dateString);
			return d;
		}
		catch(Exception ex) {
			return null;
		}
	}
	
	public static Date parseShortDate(String dateString) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
			Date d = sdf.parse(dateString);
			return d;
		}
		catch(Exception ex) {
			return null;
		}
	}
	
	public static Date parseTime(String dateString) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("HH:mm", Locale.ENGLISH);
			Date d = sdf.parse(dateString);
			return d;
		}
		catch(Exception ex) {
			return null;
		}
	}		
	
	public static String toDateString(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat(format, Locale.ENGLISH);
		return sdf.format(date);
	}
	
	public static String toShortDateString(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
		return sdf.format(date);
	}
	
	public static String toTimeString(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat("HH:mm", Locale.ENGLISH);
		return sdf.format(date);
	}
	
	
}



